<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-card title="部门信息" >
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="下级部门名称">
            <a-input placeholder="部门名称" v-decorator="['projectName', {rules:[{required:true,message:'请输入项目名称'}]}]" />
          </a-form-item>
        </a-card>
        <a-card title="部门管理员信息" style="margin-top: 10px">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="手机号(登录账号)">
            <a-input placeholder="请输入手机号" v-decorator="['phone', {rules:[{required: true,message:'请输入手机号' }]}]" />
          </a-form-item>
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="姓名">
            <a-input placeholder="请输入姓名" v-decorator="['realname', {rules:[{required:true,message:'请输入姓名'}]}]" />
          </a-form-item>
          <a-form-item :labelCol="labelCol"
                       :wrapperCol="wrapperCol"  label="性别">
            <a-select v-decorator="[ 'sex', {initialValue:1}]" placeholder="请选择性别">
              <a-select-option :value="1">男</a-select-option>
              <a-select-option :value="2">女</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="电子邮件">
            <a-input placeholder="电子邮件" v-decorator="['email', {}]" />
          </a-form-item>
        </a-card>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import {httpAction} from "@api/manage";

export default {
  name: "ProjectAddModel",
  data(){
    return{
      title:"新增人行工程",
      visible:false,
      confirmLoading:false,
      form: this.$form.createForm(this),
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      url:{
        add:'/sysProject/add'
      }
    }
  },
  methods:{
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpUrl = this.url.add;
          let method = 'post';
          debugger
          let sysProject={}
          sysProject.projectName = values.projectName
          let sysUser = Object.assign({},values)
          sysUser.username = sysUser.phone
          let formData = {sysProject:sysProject,sysUser:sysUser};
          //时间格式化
          formData.updateTime = formData.updateTime?formData.updateTime.format('YYYY-MM-DD HH:mm:ss'):null;

          httpAction(httpUrl,formData,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })

        }
      })
    },
    handleCancel () {
      this.close()
    },
    init(){
      this.visible = true
    }
  }
}
</script>

<style scoped>
/deep/.ant-card-body{
  padding-bottom: 0px;
}
</style>